package structures;
import java.awt.Component;
import java.util.Map.Entry;

import javax.swing.JList;
import javax.swing.plaf.basic.BasicComboBoxRenderer;

/**
 * Makes a combobox for a table cell editor that displays a string but
 * passes an int to the table.
 * @author darin
 *
 */
public class KvComboRenderer extends BasicComboBoxRenderer {
	/**
	 * a serial version id
	 */
	private static final long serialVersionUID = 1L;
	/**
	 * Return a component that has been configured to display the specified
	 * value. That component's paint method is then called to "render" the
	 *  cell. If it is necessary to compute the dimensions of a list because
	 *  the list cells do not have a fixed size, this method is called to
	 *  generate a component on which getPreferredSize can be invoked.
	 * @param list The JList we're painting
	 * @param value The value returned by
	 * list.getModel().getElementAt(index).
	 * @param index the cells index
	 * @param isSelected True if the specified cell was selected.
	 * @param cellHasFocus True if the specified cell has the focus.
	 * @return this, a type of JLabel in this case
	 */
	@Override
	public final Component getListCellRendererComponent(final JList list, 
			final Object value,
			final int index,
			final boolean isSelected,
			final boolean cellHasFocus)	{
		super.getListCellRendererComponent(list, value, index,
				isSelected, cellHasFocus);
		if (value != null) {
			Entry<Integer, String> item = (Entry) value;
			setText((String) item.getValue());
		}
		if (index == -1) {
			Entry<Integer, String> item = (Entry) value;
			setText((String) item.getValue());
		}
		return this;
	}
}
